package com.yonyou.brigade.third_parties.ystrip.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.order_center.model.BriTrainOrder;

import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * 云上火车票订单信息转换
 */
public class OrderConvertUtil {
    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm");

    public static BriTrainOrder convertYStripOrder2BriTrainOrder(JSONObject jsonObject) throws ParseException {
        BriTrainOrder briTrainOrder = new BriTrainOrder();
        briTrainOrder.setChannelId(jsonObject.getString("channelId"));
        briTrainOrder.setOrderNo(jsonObject.getString("OrderNo"));
        briTrainOrder.setOrderStatus(jsonObject.getString("OrderStatus"));
        briTrainOrder.setOrderStatusName(jsonObject.getString("OrderStatusName"));
        briTrainOrder.setOrderTime(jsonObject.getDate("Birthtime"));
        briTrainOrder.setPaymentPrice(jsonObject.getBigDecimal("OrderSumPrice"));
        briTrainOrder.setStatusType(jsonObject.getString("OrderType"));
        briTrainOrder.setCreateBy(jsonObject.getString("Linkman"));

//        briTrainOrder.setTrainCode(jsonObject.getString("TrainNo"));
//        briTrainOrder.setFromStation(jsonObject.getString("GoName"));
//        briTrainOrder.setToStation(jsonObject.getString("EndName"));
//
//        briTrainOrder.setTrainDate(simpleDateFormat.parse(jsonObject.getString("Departdate")));
//        briTrainOrder.setToDate(simpleDateFormat.parse(jsonObject.getString("Arrivedate")));
//        Time departTime = new Time(simpleDateFormat1.parse(jsonObject.getString("DepartTime")).getTime());
//        Time arriveTime = new Time(simpleDateFormat1.parse(jsonObject.getString("ArriveTime")).getTime());
//        briTrainOrder.setFromTime(departTime);
//        briTrainOrder.setToTime(arriveTime);

        JSONArray passengerList = jsonObject.getJSONArray("PassengerList");
        if (passengerList != null && passengerList.size() > 0){
            JSONObject passenger = passengerList.getJSONObject(0);
//            briTrainOrder.setSeatType(passenger.getString("SeatType"));
            briTrainOrder.setLinkPhone(passenger.getString("PassengerPhone"));
            briTrainOrder.setLinkName(jsonObject.getString("Passenger"));
        }

        briTrainOrder.setFromType("ystrip");
        return briTrainOrder;
    }
}
